# -*- coding: utf-8 -*-

# @Project : DDT_FrameWork
# @Author  : Mr.Deng
# @Time    : 2021/9/16 23:45

"""
alert弹窗处理操作，接受、取消、输入、获取文本
"""

from common.seleniumLibrary.base import Base
from common.tools.decorator import error_collection


class Alert(Base):

    @error_collection
    def accept_alert(self):
        """
        接受alert弹窗
        :return:
        """
        self.wait_alert_is_present().accept()
        self.Log.info("接受当前浏览器对话弹窗")

    @error_collection
    def dismiss_alert(self):
        """
        取消alert弹窗
        :return:
        """
        self.wait_alert_is_present().dismiss()
        self.Log.info("取消当前浏览器对话弹窗")

    @error_collection
    def input_alert(self, value: str):
        """
        alert弹窗中输入字段
        :param value: 输入字符串
        :return:
        """
        self.wait_alert_is_present().send_keys(value)
        self.Log.info(f"当前浏览器对话弹窗中输入：{value}")

    @error_collection
    def get_alert_text(self) -> str:
        """
        获取alert弹窗显示字段
        :return:
        """
        text = self.wait_alert_is_present().text
        self.Log.info(f"获取对话框内容：{text}")
        return text
